package com.bestcem.xm.openplatform.convert.grpc;

import com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparamsDeliverExtparamType;
import com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparamsExtparamType;
import com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparamsSource;
import com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparamsStatus;
import com.bestcem.xm.openplatform.entity.*;
import com.bestcem.xm.openplatform.grpc.client.dto.DeliverDto;
import com.bestcem.xm.openplatform.grpc.client.dto.DeliverExtDeliverMappingDto;
import com.bestcem.xm.openplatform.grpc.client.dto.DeliverExtParamsDto;
import com.bestcem.xm.openplatform.grpc.client.dto.QstructsDto;
import com.bestcem.xm.openplatform.grpc.v1.services.*;
import com.bestcem.xm.qdes.grpc.v1.services.QStruct;
import org.mapstruct.*;

import java.util.List;


@Mapper(componentModel = MappingConstants.ComponentModel.SPRING,
        collectionMappingStrategy = CollectionMappingStrategy.ADDER_PREFERRED,
        nullValueCheckStrategy = NullValueCheckStrategy.ALWAYS,
        uses = {BaseConvertMapper.class},
        imports = {FunctionOptionDeliverTtype.class, EncryptionConfigEType.class, DeliverExtparamsSource.class, DeliverExtparamsStatus.class, DeliverExtparamsExtparamType.class, DeliverExtparamsDeliverExtparamType.class, ExtParamDtype.class, ExtParamStatus.class, ExtParamEnumManageStatus.class})
public interface OpenplatformGrpcConvertMapper {

    @Mapping(target = "dtype", expression = "java(ExtParamDtype.forNumber(item.getDtype()))")
    @Mapping(target = "status", expression = "java(ExtParamStatus.forNumber(item.getStatus()))")
    @Mapping(target = "desc", source = "description")
    com.bestcem.xm.openplatform.grpc.v1.services.ExtParam toGrpcExtParam(OpenplatformExtparam item);

    List<ExtParam> toGrpcExtParamList(List<OpenplatformExtparam> item);

    @Mapping(target = "dtype", expression = "java(item.getDtype().getNumber())")
    @Mapping(target = "status", expression = "java(item.getStatusValue())")
    @Mapping(target = "description", source = "desc")
    OpenplatformExtparam toOpenplatformExtparam(com.bestcem.xm.openplatform.grpc.v1.services.ExtParam item);

    @Mapping(target = "status", expression = "java(ExtParamEnumManageStatus.forNumber(item.getStatus()))")
    com.bestcem.xm.openplatform.grpc.v1.services.ExtParamEnumManage toGrpcExtParamEnumManage(OpenplatformExtparamenummanage item);

    List<com.bestcem.xm.openplatform.grpc.v1.services.ExtParamEnumManage> toGrpcExtParamEnumManageList(List<OpenplatformExtparamenummanage> item);

    @Mapping(target = "status", expression = "java(item.getStatusValue())")
    OpenplatformExtparamenummanage toExtParamEnumManage(com.bestcem.xm.openplatform.grpc.v1.services.ExtParamEnumManage item);

    OpenplatformConditionmanage toConditionmanage(com.bestcem.xm.openplatform.grpc.v1.services.ConditionManage item);

    com.bestcem.xm.openplatform.grpc.v1.services.ConditionManage toGrpcConditionManage(OpenplatformConditionmanage item);

    List<com.bestcem.xm.openplatform.grpc.v1.services.ConditionManage> toGrpcConditionManageList(List<OpenplatformConditionmanage> item);

    OpenplatformSystemmanage toSystemmanage(com.bestcem.xm.openplatform.grpc.v1.services.SystemManage item);

    com.bestcem.xm.openplatform.grpc.v1.services.SystemManage toGrpcSystemmanage(OpenplatformSystemmanage item);

    List<com.bestcem.xm.openplatform.grpc.v1.services.SystemManage> toGrpcSystemmanageList(List<OpenplatformSystemmanage> item);

    @Mapping(target = "deliverExtparamType", expression = "java(item.getDeliverExtparamType().getNumber())")
    @Mapping(target = "source", expression = "java(item.getSourceValue())")
    @Mapping(target = "extparamType", expression = "java(item.getExtparamType().getNumber())")
    @Mapping(target = "status", expression = "java(item.getStatusValue())")
    DeliverExtParamsDto toDeliverExtParamsDto(com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparams item);

    List<DeliverExtParamsDto> toDeliverExtParamsDtoList(List<com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparams> items);

    DeliverExtDeliverMappingDto toDeliverExtDeliverMappingDto(com.bestcem.xm.deliver.grpc.v1.services.ExtDeliverMapping item);

    List<DeliverExtDeliverMappingDto> toDeliverExtDeliverMappingDtoList(List<com.bestcem.xm.deliver.grpc.v1.services.ExtDeliverMapping> items);

    @Named("deliverExtparamType")
    default DeliverExtparamsDeliverExtparamType deliverExtparamType(Integer delayFailedTtype) {
        if (delayFailedTtype == null) {
            return null;
        }
        return DeliverExtparamsDeliverExtparamType.forNumber(delayFailedTtype);
    }

    @Named("extparamsSource")
    default DeliverExtparamsSource extparamsSource(Integer extparamsSource) {
        if (extparamsSource == null) {
            return null;
        }
        return DeliverExtparamsSource.forNumber(extparamsSource);
    }

    @Named("extparamsExtparamType")
    default DeliverExtparamsExtparamType extparamsExtparamType(Integer extparamsSource) {
        if (extparamsSource == null) {
            return null;
        }
        return DeliverExtparamsExtparamType.forNumber(extparamsSource);
    }

    @Mapping(target = "deliverExtparamType", source = "deliverExtparamType", qualifiedByName = "deliverExtparamType")
    @Mapping(target = "source", source = "source", qualifiedByName = "extparamsSource")
    @Mapping(target = "extparamType", source = "extparamType", qualifiedByName = "extparamsExtparamType")
    @Mapping(target = "status", expression = "java(DeliverExtparamsStatus.forNumber(item.getStatus()))")
    com.bestcem.xm.deliver.grpc.v1.services.DeliverExtparams toGrpcDeliverExtparams(DeliverExtParamsDto item);

    @Mapping(target = "ttype", expression = "java(item.getTtypeValue())")
    @Mapping(target = "status", expression = "java(item.getStatusValue())")
    @Mapping(target = "channel", expression = "java(item.getChannelValue())")
    @Mapping(target = "scenes", expression = "java(item.getScenesValue())")
    @Mapping(target = "delayFailedTtype", expression = "java(item.getDelayFailedttypeValue())")
    @Mapping(target = "delayFailedTime", source = "delayFailedtime")
    @Mapping(target = "awardUseType", expression = "java(item.getAwardUseTypeValue())")
    DeliverDto toDeliverDto(com.bestcem.xm.deliver.grpc.v1.services.Deliver item);

    @Mapping(target = "status", expression = "java(qstruct.getStatusValue())")
    QstructsDto toQstructsDto(QStruct qstruct);

    @Mapping(target = "EType", expression = "java(item.getETypeValue())")
    OpenplatformEncryptionconfig toEncryptionconfig(com.bestcem.xm.openplatform.grpc.v1.services.EncryptionConfig item);

    @Mapping(target = "EType", expression = "java(EncryptionConfigEType.forNumber(item.getEType()))")
    com.bestcem.xm.openplatform.grpc.v1.services.EncryptionConfig toGrpcEncryptionConfig(OpenplatformEncryptionconfig item);

    List<com.bestcem.xm.openplatform.grpc.v1.services.EncryptionConfig> toGrpcEncryptionConfigList(List<OpenplatformEncryptionconfig> item);

    @Mapping(target = "deliverTtype", expression = "java(FunctionOptionDeliverTtype.forNumber(item.getDeliverTtype()))")
    FunctionOption toGrpcFunctionOption(OpenplatformFunctionoption item);
}
